package com.damie.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dadie.Domain.ShopDomain;
import com.dadie.Dto.ShopDto;
import com.dadie.parame.ShopParame;
import com.dadie.parame.UpdateShopParam;
import com.damie.common.commonutils.R;
import com.damie.service.ShopService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Alon
 * @since 2021-01-23
 */
@Api(value="商城controller",tags={"后台:商城商品管理"})
@RestController
@CrossOrigin("*")
@RequestMapping("/damie/shop")
public class ShopController {

    @Resource
    private ShopService shopService;

    @ApiOperation("新增商品入库或增加商品请求")
    @PostMapping("addProduct")
    public R addProduct(@RequestBody ShopParame shopParame){
        ShopDto shopDto = shopService.addProduct(shopParame);
        return R.ok().data("shop",shopDto);
    }

    @ApiOperation("条件分页查询所有在库商品")
    @GetMapping("selectAllProduct")
    public R selectAllProduct(Integer index,Integer size,String shopName){
        Page<ShopDto> shopDtoPage = shopService.selectAllProduct(index, size, shopName );
        return R.ok().data("all",shopDtoPage);
    }

    @ApiOperation("删除库中商品")
    @DeleteMapping("deleteByIdProduct")
    public R deleteByIdProduct(String pid){
        ShopDto shopDto = shopService.deleteByIdProduct(pid);
        return R.ok().data("date",shopDto);
    }

    @ApiOperation("修改库中商品")
    @PostMapping("updateByProduct")
    public R updateByProduct(@RequestBody UpdateShopParam shopParame){
        /*
        * 修改库中商品数量传入多少就是多少
        * 修改库中默认所需积分
        * 修改库中的商品名字
        * 修改上架的商品的名字
        **/
        ShopDto shopDto = shopService.updateByProduct(shopParame);
        return R.ok().data("date",shopDto);
    }

    @ApiOperation("减少库中商品数量")
    @PostMapping("updateByProductNum")
    public R updateByProductNum(String pid,Integer num){
        /*
         * 减少库中的数量
         **/
        ShopDto shopDto = shopService.updateByProductNum(pid,num);
        return R.ok().data("date",shopDto);
    }

}

